<?php
//print_r($_POST);
?>

<style>
.table th { border:1px solid #aaa;
			background: #e9e9e9;
			color: #666666;
			padding: 4px 8px;
			text-align: left;
			white-space: nowrap;
			height: 32px;
			line-height: 32px;}
.table td {
	border:1px solid #aaa;
	
}
</style>

<script>
$("document").ready(function(){


	$( "#category_123" ).click(function(){
	 	$(this).autocomplete("search"); 
	}).autocomplete({
        minLength: 0,
        source: function(request, response ) {
                $.ajax({
                    url: "/client/category_josn",
                    dataType: "json",
                    data:{
						query: request.term
                    },
                    success: function( data ) {
                        response( $.map( data, function( item ) {
                        return {
							label: item.value,
							value: item.value
                        }
                        }));
                    }
          
                });
	    },
        focus: function() {
        	//alert('aaa');
          return false;
        }
        ,
        select: function( event, ui ) {
			var terms=new Array();
			if(this.value!="")
				terms = this.value.split(", ");
			terms.pop();
			terms.push( ui.item.value );
			terms.push( "" );
			this.value = terms.join( ", " );
			return false;
        }
      });




	$( "#nationality1" ).click(function(){
	 	$(this).autocomplete("search"); 
	}).autocomplete({
        minLength: 0,
        source: function(request, response ) {
                $.ajax({
                    url: "/client/nationality_josn",
                    dataType: "json",
                    data:{
						query: request.term
                    },
                    success: function( data ) {
                        response( $.map( data, function( item ) {
                        return {
							label: item.value,
							value: item.value
                        }
                        }));
                    }
          
                });
	    },
        focus: function() {
        	//alert('aaa');
          return false;
        }
        ,
        select: function( event, ui ) {
			var terms=new Array();
			if(this.value!="")
				terms = this.value.split(", ");
			terms.pop();
			terms.push( ui.item.value );
			terms.push( "" );
			this.value = terms.join( ", " );
			return false;
        }
      });

$( "#customer_source_123" ).click(function(){
	 	$(this).autocomplete("search"); 
	}).autocomplete({
        minLength: 0,
        source: function(request, response ) {
                $.ajax({
                    url: "/client/customer_source_josn",
                    dataType: "json",
                    data:{
						query: request.term
                    },
                    success: function( data ) {
                        response( $.map( data, function( item ) {
                        return {
							label: item.value,
							value: item.value
                        }
                        }));
                    }
          
                });
	    },
        focus: function() {
        	//alert('aaa');
          return false;
        }
        ,
        select: function( event, ui ) {
			var terms=new Array();
			if(this.value!="")
				terms = this.value.split(", ");
			terms.pop();
			terms.push( ui.item.value );
			terms.push( "" );
			this.value = terms.join( ", " );
			return false;
        }
});






$( "#building_name123" )
      .bind( 'focus', function(){ $(this).autocomplete("search"); } ).bind( 'click', function(){ $(this).autocomplete("search"); } )
      .autocomplete({
        minLength: 0,
        source: function(request, response ) {
                $.ajax({
                    url: "/client/building_name_josn",
                    dataType: "json",
                    data:{
						query: request.term
                    },
                    success: function( data ) {
                        response( $.map( data, function( item ) {
                        return {
						label: item.value,
						value: item.value
                        }
                        }));
                    }
                });
	    },
        focus: function() {
          return false;
        }
      });



$( "#importance_123" ).click(function(){
	 	$(this).autocomplete("search"); 
	}).autocomplete({
        minLength: 0,
        source: function(request, response ) {
                $.ajax({
                    url: "/client/importance_josn",
                    dataType: "json",
                    data:{
						query: request.term
                    },
                    success: function( data ) {
                        response( $.map( data, function( item ) {
                        return {
							label: item.value,
							value: item.value
                        }
                        }));
                    }
          
                });
	    },
        focus: function() {
        	//alert('aaa');
          return false;
        }
        ,
        select: function( event, ui ) {
			var terms=new Array();
			if(this.value!="")
				terms = this.value.split(", ");
			terms.pop();
			terms.push( ui.item.value );
			terms.push( "" );
			this.value = terms.join( ", " );
			return false;
        }
});


	  




});
      
</script>
 
 <link href="/css/bootstrap/dist/css/bootstrap.css" type="text/css" rel="stylesheet">

<form  method="post"  id="userinfo">
		
		<table class="table" >
			<tbody>
				<tr>
				    <th width="10%">客戶姓名</th>
				    <td width="35%">
						<input type="text" id="name" name="name"  value="<?=!empty($_POST["name"]) ?$_POST["name"]:""?>" >
				    	<div id="search_user_div"></div>
				    </td>
				    
				    <th width="10%">特徴</th>
				    <td width="45%">
				    	<input type="text" id="recommended" name="recommended"  value="<?=!empty($_POST["recommended"]) ?$_POST["recommended"]:""?>"  >
				    </td>
				  </tr>
				  
				  <tr>
				    <th>
				    	<div id="icon-plus">
				    		<a onclick="query_more();" class="additem">
				    			<i style="color:#25EA41" class="icon-plus" id="query_more_icon">&nbsp;&nbsp;</i>
				    		</a>&nbsp;重要性
				    	</div>
					</th>
					
				     <td>
						<input id="importance_123" name="importance" size="46"  style="width:280px;"   value="<?=!empty($_POST["importance"]) ?$_POST["importance"]:""?>" />
				    </td>
				    
				    <th>國籍</th>
				    <td>
						<input id="nationality1" name="nationality" size="50"     style="width:280px;"  value="<?=!empty($_POST["nationality"]) ?$_POST["nationality"]:""?>" />
				    </td>
				  </tr>
			</tbody>

			<!--
			<tbody style="display:none;" id="query_more">	  
			-->

			<tbody style="display:;" id="query_more">	  
				  <tr>
				    <th>
				    	住家地址
				    </th>
				    <td>
				    	<input type="text"
				    	  value="<?=!empty($_POST["home_address"]) ?$_POST["home_address"]:""?>"    
				    	 style="width:280px;"  class="post" id="home_address123" name="home_address" onclick="show_address('home_address123');">
				    </td>
				    <th>大樓名稱</th>
				    <td>
					<input id="building_name123" name="building_name" size="50" style="width:280px;"  value="<?=!empty($_POST["building_name"]) ?$_POST["building_name"]:""?>"   />
				    </td>
				  </tr>
				  <tr>
				  	<th>公司名稱</th>
				  	<td><input type="text" style="width:280px;"  class="post" id="company_name" name="company_name"  value="<?=!empty($_POST["company_name"]) ?$_POST["company_name"]:""?>" ></td>
				  	<th>類別</th>
				  	<td>
						<input id="category_123" name="category" size="50" style="width:280px;"  value="<?=!empty($_POST["category"]) ?$_POST["category"]:""?>"   />
				  	</td>
				  </tr>
				  <tr>
				    <th>電話</th>
				    <td>
				    	<input type="text" style="width:280px;"  class="post" id="mobile" name="mobile"  value="<?=!empty($_POST["mobile"]) ?$_POST["mobile"]:""?>" >
				    </td>
				    <th>客戶來源</th>
				    <td>
						<input id="customer_source_123" name="customer_source" size="50" style="width:280px;"   value="<?=!empty($_POST["customer_source"]) ?$_POST["customer_source"]:""?>"  />
					</div>
					</td>
				  </tr>
				  <tr>
				    <th>建檔日期</th>
				   <td>
				    	<input type="text"  style="width:92px;" onClick="WdatePicker()" class="post Wdate" name="sctime" id="sctime"  value="<?=!empty($_POST["sctime"]) ?$_POST["sctime"]:""?>" > ~ 
				    	<input type="text" style="width:92px;" onClick="WdatePicker()" class="post Wdate" name="ectime" id="ectime"  value="<?=!empty($_POST["ectime"]) ?$_POST["ectime"]:""?>" >
				    </td>
				    <th>生日</th>
				    <td>
				    	<input type="text" class="Wdate" onClick="WdatePicker()" style="width:92px;" id="sbirthday" name="sbirthday"  value="<?=!empty($_POST["sbirthday"]) ?$_POST["sbirthday"]:""?>" > ~
				    	<input type="text" class="Wdate" onClick="WdatePicker()" style="width:92px;" id="ebirthday" name="ebirthday"  value="<?=!empty($_POST["ebirthday"]) ?$_POST["ebirthday"]:""?>" >
				    </td>
				  </tr>
				  <tr>
				    <th>寄發刊物</th>
				    <td>
				    	<input type="radio" value="Y" class="post" id="send_publication" name="send_publication"  <?=!empty($_POST["send_publication"]) ?($_POST["send_publication"]=="Y"?'CHECKED':"" ) :""?>>Y&nbsp;&nbsp;
				    	<input type="radio" value="N" class="post" id="send_publication" name="send_publication"  <?=!empty($_POST["send_publication"]) ?($_POST["send_publication"]=="N"?'CHECKED':"" ) :""?> >N
				    </td>
				    <th>寄發EDM</th>
				    <td><input type="radio" value="Y" class="post" id="send_email" name="send_email"  <?=!empty($_POST["send_email"]) ?($_POST["send_email"]=="Y"?'CHECKED':"" ) :""?> >Y&nbsp;&nbsp;
				    	<input type="radio" value="N" class="post" id="send_email" name="send_email"    <?=!empty($_POST["send_email"]) ?($_POST["send_email"]=="N"?'CHECKED':"" ) :""?>>N</td>
				  </tr>
				  <tr>
				    <th>送禮</th>
				    <td><input type="radio" class="post" value="Y" id="gifts" name="gifts"  <?=!empty($_POST["gifts"]) ?($_POST["gifts"]=="Y"?'CHECKED':"" ) :""?>   >Y&nbsp;&nbsp;
				    	<input type="radio" class="post" value="N" id="gifts" name="gifts"  <?=!empty($_POST["gifts"]) ?($_POST["gifts"]=="N"?'CHECKED':"" ) :""?>  >N</td>
				    <th>經紀人</th>
				    <td>
				    	

				    	<select name="broker">
				    		<option></option>
				    		<?php 
				    			foreach ($users as $user) {
				    				 
				    		?>
				    			
								<option value="<?=$user->users_id;?>"
									<?php 
									if(!empty($_POST["broker"]) )
										if($user->users_id==$_POST["broker"]){
											echo 'SELECTED';
										}									
									?>
									 > <?=$user->name?> </option>
				    		<?php 
				    		
								} 
							?>				    		
				    	</select>	
				    </td>
				  </tr>				  
				  <tr>
				    <th>關鍵字</th>
				    <td colspan="3"><input type="text" style="width:21%;" class="post" id="keywords" name="keywords"  value="<?=!empty($_POST["keywords"]) ?$_POST["keywords"]:""?>" ></td>
				  </tr>
			</tbody>
			<tfoot>
			  <tr>
				<td>&nbsp;</td>
				<td colspan="3">
				<input type="submit" value="查詢確認" class="input_background">
				</td>
			  </tr>
			</tfoot>

		</table>
		  
		


		<div id="address_select" style="display: none;">
							<div id="city_div"  style="float:left;padding:10px">
								<h3>縣市</h3>
								  <select onchange="city_choose();" size="20" id="city">
									<option value="">請選擇</option>
									<?
									foreach($address_city as $key=>$val){
									?>
										<option <? if($val->id=="1") echo "selected"; ?>  value="<?=$val->id?>"><?=$val->name?></option>
									<?
									}
									?>
									</select>
							</div>
							
							<div id="area_div"  style="float:left;padding:10px">
									<h3>區域</h3>
									<select onchange="county_choose();" size="20" id="country">
									  <option value="">請選擇</option>
									<?
									foreach($address_county as $key=>$val){
									?>
									  <option value="<?=$val->id?>" <? if($val->id=="1") echo "selected"; ?>><?=$val->name?></option>
									<?
									}
									?>
									</select>
							</div>
							
							<div id="street_div" style="float:left;padding:10px">
									<h3>街道</h3>
									<select onchange="street_choose()" size="20" id="street">
										<option value="">請選擇</option>
									</select>
							</div>
							
							<div id="other_div" style="float:left;padding:10px">
									<h3>其它</h3>

									<div>
										<input type="button" onclick="word_choose('number_1')" value="1" class="button" name="number_1" id="number_1">
										  <input type="button" onclick="word_choose('number_2')" value="2" class="button" name="number_2" id="number_2">
										  <input type="button" onclick="word_choose('number_3')" value="3" class="button" name="number_3" id="number_3">
										  <input type="button" onclick="word_choose('number_4')" value="4" class="button" name="number_4" id="number_4">
										  <input type="button" onclick="word_choose('number_5')" value="5" class="button" name="number_5" id="number_5">
									</div>
									<div>
										  <input type="button" onclick="word_choose('number_6')" value="6" class="button" name="number_6" id="number_6">
										  <input type="button" onclick="word_choose('number_7')" value="7" class="button" name="number_7" id="number_7">
										  <input type="button" onclick="word_choose('number_8')" value="8" class="button" name="number_8" id="number_8">
										  <input type="button" onclick="word_choose('number_9')" value="9" class="button" name="number_9" id="number_9">
										  <input type="button" onclick="word_choose('number_0')" value="0" class="button" name="number_0" id="number_0">
									</div>


									<div>
										<input type="button" onclick="word_choose('road')" value="路" class="button" name="road" id="road">
										<input type="button" onclick="word_choose('word_street')" value="街" class="button" name="word_street" id="word_street">
										<input type="button" onclick="word_choose('paragraph')" value="段" class="button" name="paragraph" id="paragraph">
										<input type="button" onclick="word_choose('lane')" value="巷" class="button" name="lane" id="lane">
									</div>

									<div>
										<input type="button" onclick="word_choose('get')" value="弄" class="button" name="get" id="get">
										<input type="button" onclick="word_choose('number')" value="號" class="button" name="number" id="number">
										<input type="button" onclick="word_choose('floor')" value="樓" class="button" name="floor" id="floor">
										<input type="button" onclick="word_choose('room')" value="室" class="button" name="room" id="room">
									</div>
									

									

									
									<div>
										<input type="button" onclick="word_choose('the')" value="之" class="button" name="the" id="the">
										<input type="button" onclick="word_choose('village')" value="村" class="button" name="village" id="village">
										<input type="button" onclick="word_choose('in')" value="里" class="button" name="in" id="in">
										<input type="button" onclick="word_choose('neighbor')" value="鄰" class="button" name="neighbor" id="neighbor">
									</div>

									
									
									<div>
										
										<input type="button" onclick="word_choose('del')" value="Del" class="button" name="del" id="del">
									</div>
									
							</div>
							<div style="clear: both;"></div>
							<div id="addr_div" style="padding:10px">
								<input type="text" value="" id="address">
							</div>

            </div>



		</form>
	